{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "3a512f97-a588-4096-a679-a60a7fae4bf9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "type"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "class MyClass(object):\n",
    "    \"\"\"a class\"\"\"\n",
    "    x=5\n",
    "MyClass.__class__"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "1e088381-1134-41f0-9a46-ad1e87486c68",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5\n"
     ]
    }
   ],
   "source": [
    "c = MyClass()\n",
    "print(c.x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "f8ff80b8-5fab-4d7f-9c74-d7da1a4fe60d",
   "metadata": {},
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "'MyClass' object has no attribute 'x'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[12], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28;01mdel\u001b[39;00m \u001b[43mc\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mx\u001b[49m\n\u001b[1;32m      2\u001b[0m \u001b[38;5;66;03m# 示例c可以读取x属性， 但是不能删除， 因为实际上读取的是类MyClass的x属性\u001b[39;00m\n",
      "\u001b[0;31mAttributeError\u001b[0m: 'MyClass' object has no attribute 'x'"
     ]
    }
   ],
   "source": [
    "del c.x\n",
    "# 示例c可以读取x属性， 但是不能删除， 因为实际上读取的是类MyClass的x属性"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "9554fd24-1745-4c0d-a39e-02031fd1965a",
   "metadata": {},
   "outputs": [],
   "source": [
    "c.x=6"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "d20bd17d-9688-4a1c-9f35-4d878b4192d8",
   "metadata": {},
   "outputs": [],
   "source": [
    "del c.x\n",
    "# 实例c定义了自己的x属性后， 就可以进行删除操作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "91484cc7-ff74-498d-9761-04e24cd7709d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c.x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "f230ce4d-827a-4005-ac3c-4cdd39d86ea9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "8"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c.x=8\n",
    "c.x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "99fe63f9-db2b-46f5-947c-ff3370e56771",
   "metadata": {},
   "outputs": [],
   "source": [
    "class ClassB(object):\n",
    "    \"\"\"class B def\"\"\"\n",
    "    def meth1(self):\n",
    "        print(\"In meth1\")\n",
    "b=ClassB()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "86d19354-4e74-4953-9438-90c6637a3a95",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "In meth1\n"
     ]
    }
   ],
   "source": [
    "ClassB.meth1(12)\n",
    "# 这样调用也行？？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "2594ab2a-a916-4acf-935f-20307e41a9e8",
   "metadata": {},
   "outputs": [],
   "source": [
    "class ClassD(object):\n",
    "    \"\"\"class D\"\"\"\n",
    "    \n",
    "    @staticmethod\n",
    "    def foo():\n",
    "        print(\"In foo\")\n",
    "        \n",
    "    @classmethod\n",
    "    def foo2():\n",
    "        print(\"In foo2\")\n",
    "# 添加staticmethod修饰符只是为了类的实例可以访问"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "e74acf22-9196-4f52-b39e-5d4e70439f9e",
   "metadata": {},
   "outputs": [],
   "source": [
    "d=ClassD()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "e41cb8d1-8da9-4816-9438-ac5f690ca4fc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "In foo\n"
     ]
    }
   ],
   "source": [
    "d.foo()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "2be4155a-6494-4feb-b752-04f49fcd9b19",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "In foo\n"
     ]
    }
   ],
   "source": [
    "ClassD.foo()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "dd9d4e83-c814-460b-b189-fc478ac4b2dd",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "ClassD.foo2() takes 0 positional arguments but 1 was given",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[33], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43md\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mfoo2\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n",
      "\u001b[0;31mTypeError\u001b[0m: ClassD.foo2() takes 0 positional arguments but 1 was given"
     ]
    }
   ],
   "source": [
    "d.foo2()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "a9fbee4b-277d-4410-a6e8-3847fa99bfc0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "In A-foo\n",
      "In B-foo\n"
     ]
    }
   ],
   "source": [
    "class A(object):\n",
    "\n",
    "    def foo(self):\n",
    "        print(\"In A-foo\")\n",
    "\n",
    "\n",
    "class B(A):\n",
    "    \n",
    "    def foo(self):\n",
    "        super().foo()\n",
    "        print(\"In B-foo\")\n",
    "b=B()\n",
    "b.foo()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "fdee000c-46b1-427d-b654-94edf991f2a6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "type"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(super)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5345ea7d-82e6-4a42-8447-b794d3541a06",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
